package com.ruoyi.project.zerocarbon.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.zerocarbon.domain.DeclareMediaCoverage;
import com.ruoyi.project.zerocarbon.service.IDeclareMediaCoverageService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 媒体报道情况Controller
 * 
 * @author ruoyi
 * @date 2022-03-13
 */
@RestController
@RequestMapping("/zerocarbon/coverage")
public class DeclareMediaCoverageController extends BaseController
{
    @Autowired
    private IDeclareMediaCoverageService declareMediaCoverageService;

    /**
     * 查询媒体报道情况列表
     */
    @PreAuthorize("@ss.hasPermi('zerocarbon:coverage:list')")
    @GetMapping("/list")
    public TableDataInfo list(DeclareMediaCoverage declareMediaCoverage)
    {
        startPage();
        List<DeclareMediaCoverage> list = declareMediaCoverageService.selectDeclareMediaCoverageList(declareMediaCoverage);
        return getDataTable(list);
    }

    /**
     * 导出媒体报道情况列表
     */
    @PreAuthorize("@ss.hasPermi('zerocarbon:coverage:export')")
    @Log(title = "媒体报道情况", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(DeclareMediaCoverage declareMediaCoverage)
    {
        List<DeclareMediaCoverage> list = declareMediaCoverageService.selectDeclareMediaCoverageList(declareMediaCoverage);
        ExcelUtil<DeclareMediaCoverage> util = new ExcelUtil<DeclareMediaCoverage>(DeclareMediaCoverage.class);
        return util.exportExcel(list, "媒体报道情况数据");
    }

    /**
     * 获取媒体报道情况详细信息
     */
    @PreAuthorize("@ss.hasPermi('zerocarbon:coverage:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(declareMediaCoverageService.selectDeclareMediaCoverageById(id));
    }

    /**
     * 新增媒体报道情况
     */
    @PreAuthorize("@ss.hasPermi('zerocarbon:coverage:add')")
    @Log(title = "媒体报道情况", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DeclareMediaCoverage declareMediaCoverage)
    {
        return toAjax(declareMediaCoverageService.insertDeclareMediaCoverage(declareMediaCoverage));
    }

    /**
     * 修改媒体报道情况
     */
    @PreAuthorize("@ss.hasPermi('zerocarbon:coverage:edit')")
    @Log(title = "媒体报道情况", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DeclareMediaCoverage declareMediaCoverage)
    {
        return toAjax(declareMediaCoverageService.updateDeclareMediaCoverage(declareMediaCoverage));
    }

    /**
     * 删除媒体报道情况
     */
    @PreAuthorize("@ss.hasPermi('zerocarbon:coverage:remove')")
    @Log(title = "媒体报道情况", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(declareMediaCoverageService.deleteDeclareMediaCoverageByIds(ids));
    }
}
